package com.example.bomb;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.SaveListener;

public class RegActivity extends AppCompatActivity {
    private EditText edtUserName;
    private EditText edtPassword;
    private EditText edtName;
    private EditText edtAge;
    private Button btnSign;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reg);

        edtPassword = findViewById(R.id.edt_password);
        edtUserName = findViewById(R.id.edt_username);
        edtName = findViewById(R.id.edt_name);
        edtAge = findViewById(R.id.edt_age);


        btnSign = findViewById(R.id.btn_sign);

        btnSign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                regUser();
            }
        });

    }

    private void regUser() {
        String username =edtUserName.getText().toString();
        String password = edtPassword .getText().toString();
        String name = edtName.getText().toString();
        int age = Integer.valueOf(edtAge.getText().toString());

        MyUser bmobUser = new MyUser();
        bmobUser.setUsername(username);
        bmobUser.setPassword(password);
        bmobUser.setName(name);
        bmobUser.setAge(age);

        bmobUser.signUp(new SaveListener<BmobUser>() {
            @Override
            public void done(BmobUser bmobUser, BmobException e) {
                if(e ==null){
                    Toast.makeText(RegActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
                }
            }
        });
    }
}


